Shallow copy in python and adding another array to list

40

import copy
list1 = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]
list2 = copy.copy(list1)
list1.append([10, 11, 12])
print("Old list:", list1)
print("New list:", list2)

Comments

Submit
0 Comments